<template>
  <div>
    <el-form ref="form" label-width="100px" :model="form" :rules="rules" class="form-width-80">
      <el-form-item prop="password_old" label="当前密码:">
        <el-input v-model="form.password_old" placeholder="请输入原登录密码" show-password/>
      </el-form-item>
      <el-form-item prop="password" label="新密码:">
        <el-input v-model="form.password" placeholder="请输入新登录密码" show-password/>
      </el-form-item>
      <el-form-item prop="password_r" label="再输一次:">
        <el-input v-model="form.password_r" placeholder="请输入登录密码" show-password/>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="changePwd('form')">确 定</el-button>
      <el-button type="warning" @click="onClose">取 消</el-button>
      
    </span>
  </div>
</template>
<script>
export default {
  computed:{
    model(){
      return this.$store.state.user.model
    }
  },
  data() {
    return {
      rules: {
        password_old: [{ required: true, message: "请输入原登录密码", trigger: "blur" }],
        password: [{ required: true, message: "请输入新登录密码", trigger: "blur" }],
        password_r: [{ required: true, message: "请输入新登录密码", trigger: "blur" }]
      },
      form:{
        password_old:'',
        password:'',
        password_r:'',
      },
    };
  },
  methods: {
    changePwd(formName) {
      if(this.form.password_r!=this.form.password){
        this.$msg_ok('error','两次密码不一致')
        return
      }else if(this.form.password_old==this.form.password){
        this.$msg_ok('error','新密码不能为原密码')
        return
      }
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.get(`/${this.model}/${this.model}/pwd`, this.form, "POST").then(e => {
            this.$msg_ok("success", "修改成功");
            this.onClose();
          });
        }
      });
    },
    onClose(){
      this.$emit('onClose')
    }
  }
};
</script>
>
